package com.ruoyi.service.impl;

import com.ruoyi.entity.TCustomer;
import com.ruoyi.dao.TCustomerDao;
import com.ruoyi.service.TCustomerService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (TCustomer)表服务实现类
 *
 * @author makejava
 * @since 2025-01-01 20:37:32
 */
@Service("tCustomerService")
public class TCustomerServiceImpl implements TCustomerService {
    @Resource
    private TCustomerDao tCustomerDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TCustomer queryById(Integer id) {
        return this.tCustomerDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tCustomer 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TCustomer> queryByPage(TCustomer tCustomer, PageRequest pageRequest) {
        long total = this.tCustomerDao.count(tCustomer);
        return new PageImpl<>(this.tCustomerDao.queryAllByLimit(tCustomer, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tCustomer 实例对象
     * @return 实例对象
     */
    @Override
    public TCustomer insert(TCustomer tCustomer) {
        this.tCustomerDao.insert(tCustomer);
        return tCustomer;
    }

    /**
     * 修改数据
     *
     * @param tCustomer 实例对象
     * @return 实例对象
     */
    @Override
    public TCustomer update(TCustomer tCustomer) {
        this.tCustomerDao.update(tCustomer);
        return this.queryById(tCustomer.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.tCustomerDao.deleteById(id) > 0;
    }
}
